// -----------------------------------------------------------------------
// <copyright file="ProgressWorkEN.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    
    /// <summary>
    /// Class ProgressWork
    /// </summary>
    public class ProgressWorkEN : EntityEN
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgressWorkEN" /> class
        /// </summary>
        public ProgressWorkEN()
        {
            this.ProgressWorkId = 0;
            this.ProfileTypeProgressId = 0;
            this.ProfileId = 0;
            this.FinishDate = null;
            this.StartDate = null;
            this.Status = string.Empty;
            this.Time = string.Empty;
        }
        
        /// <summary>
        /// Gets or sets ProgressWorkId
        /// </summary>
        public int ProgressWorkId { get; set; }
        
        /// <summary>
        /// Gets or sets ProfileTypeProgressId
        /// </summary>
        public int ProfileTypeProgressId { get; set; }
        
        /// <summary>
        /// Gets or sets ProfileId
        /// </summary>
        public int ProfileId { get; set; }
        
        /// <summary>
        /// Gets or sets FinishDate
        /// </summary>
        public DateTime? FinishDate { get; set; }

        /// <summary>
        /// Gets or sets the start date.
        /// </summary>
        /// <value>
        /// The start date.
        /// </value>
        public DateTime? StartDate { get; set; }
        
        /// <summary>
        /// Gets or sets Status
        /// </summary>
        public string Status { get; set; }
        
        /// <summary>
        /// Gets or sets Time
        /// </summary>
        public string Time { get; set; }

        /// <summary>
        /// Gets ProfileTypeProgress
        /// </summary>
        public ProfileTypeProgressEN ProfileTypeProgress
        {
            get
            {
                try
                {
                    ProfileTypeProgressEN profileTypeProgress = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeProgressGetById, this.ProfileTypeProgressId);

                    while (reader.Read())
                    {
                        profileTypeProgress = new ProfileTypeProgressEN();

                        if (!reader.IsDBNull(0))
                        {
                            profileTypeProgress.ProfileTypeProgressId = reader.GetInt32(0);
                        }
                        
                        if (!reader.IsDBNull(1))
                        {
                            profileTypeProgress.ProgressId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            profileTypeProgress.ProfileTypeId = reader.GetInt32(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            profileTypeProgress.DecideDays = reader.GetInt32(3);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return profileTypeProgress;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets Profile
        /// </summary>
        public ProfileEN Profile
        {
            get
            {
                try
                {
                    ProfileEN profile = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileGetById, this.ProfileId);

                    while (reader.Read())
                    {
                        profile = new ProfileEN();

                        if (!reader.IsDBNull(0))
                        {
                            profile.ProfileId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            profile.ProfileStatusId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            profile.ProfileTypeId = reader.GetInt32(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            profile.LevelId = reader.GetInt16(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            profile.StorageLocationProfileListId = reader.GetInt32(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            profile.CreateUserId = reader.GetInt32(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            profile.Code = reader.GetString(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            profile.Name = reader.GetString(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            profile.SmsGet = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            profile.Email = reader.GetString(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            profile.CreateDate = reader.GetDateTime(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            profile.ReceivingDate = reader.GetDateTime(11);
                        }

                        if (!reader.IsDBNull(12))
                        {
                            profile.AppointmentDate = reader.GetDateTime(12);
                        }

                        if (!reader.IsDBNull(13))
                        {
                            profile.Object = reader.GetBoolean(13);
                        }

                        if (!reader.IsDBNull(14))
                        {
                            profile.SettlementDate = reader.GetDateTime(14);
                        }

                        if (!reader.IsDBNull(15))
                        {
                            profile.Notes = reader.GetString(15);
                        }

                        if (!reader.IsDBNull(16))
                        {
                            profile.Attachments = reader.GetString(16);
                        }

                        if (!reader.IsDBNull(17))
                        {
                            profile.ContentWork = reader.GetString(17);
                        }

                        if (!reader.IsDBNull(18))
                        {
                            profile.IsDelete = reader.GetBoolean(18);
                        }

                        if (!reader.IsDBNull(19))
                        {
                            profile.OrganName = reader.GetString(19);
                        }

                        if (!reader.IsDBNull(20))
                        {
                            profile.Address = reader.GetString(20);
                        }

                        if (!reader.IsDBNull(21))
                        {
                            profile.Phone = reader.GetString(21);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return profile;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets WorkflowProfiles
        /// </summary>
        public IList<WorkflowProfileEN> WorkflowProfiles
        {
            get
            {
                try
                {
                    IList<WorkflowProfileEN> lstWorkflowProfile = new List<WorkflowProfileEN>();
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneWorkflowProfileGetByProgressWorkId, this.ProgressWorkId);
                    while (reader.Read())
                    {
                        WorkflowProfileEN workflowProfile = new WorkflowProfileEN();

                        if (!reader.IsDBNull(0))
                        {
                            workflowProfile.WorkflowProfileId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            workflowProfile.ProfileId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            workflowProfile.WorkflowId = reader.GetInt32(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            workflowProfile.NodeId = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            workflowProfile.SendUserId = reader.GetInt32(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            workflowProfile.MainUserId = reader.GetInt32(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            workflowProfile.ProgressWorkId = reader.GetInt32(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            workflowProfile.IsCurrent = reader.GetBoolean(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            workflowProfile.StartDate = reader.GetDateTime(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            workflowProfile.EndDate = reader.GetDateTime(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            workflowProfile.Role = reader.GetString(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            workflowProfile.RW = reader.GetBoolean(11);
                        }

                        if (!reader.IsDBNull(12))
                        {
                            workflowProfile.SendDepartmentId = reader.GetInt32(12);
                        }

                        if (!reader.IsDBNull(13))
                        {
                            workflowProfile.MainDepartmentId = reader.GetInt32(13);
                        }

                        lstWorkflowProfile.Add(workflowProfile);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstWorkflowProfile;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
